//app.js
var utils = require('utils/utils.js');
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    // wx.setStorageSync('token', 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoiaDR0dXZDUUxNSWNlUFVjeXdSQkhMRkY5VVI3OGxsNXdoSkRiOTEzL1pVTFdUbnpsNFVZVm1oZXpVTis5Y3hkUiJ9.YMTtOKabBtj3ocn0qIVQ_PY_DjBh38h0s6AnPoYFh28')
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
    wx.getSystemInfo({ // 获取设备信息
      success: (res) => {
        this.globalData.systeminfo = res
      },
    })
    // 获得胶囊按钮位置信息
    this.globalData.headerBtnPosi = wx.getMenuButtonBoundingClientRect()
    this.setNavSize() //通过获取系统信息计算导航栏高度
  },
  onHide: function () {
    let pages = getCurrentPages();
    let whiteList = [
      'userPageB/pages/userStore/cardDetail/cardDetail',
      'ecCanvas/pages/myShareholderCard/otherCarddetail/otherCarddetail',
      'ecCanvas/pages/myShareholderCard/honorShare/honorShare',
      'pages/pay/payList/payList',
    ]
    console.log("pages['0'].route", pages)
    whiteList.forEach(item => {
      if (item == pages['0'].route) {
        wx.switchTab({
          url: '/pages/userMarket/userMarket'
        })
      }
    })



  },
  http: { //这里配置我们需要的方法
    onepost: utils.onepost,
    twopost: utils.twopost,
    get: utils.get,
  },
  globalData: {
    userInfo: null,
    systeminfo: {}, // 系统信息
    headerBtnPosi: {}, // 胶囊按钮位置信息
    headerHeight: '',
    // imgHttp: 'https://bee.xiaodaiyan.com/',
    // imgHttp: 'https://www.milianmeng.net/',
    imgHttp: '',
    // contractHttp: 'https://bee.xiaodaiyan.com/group1/M00/00/5E/rBAAD2CSSTqAFeLrAAA1E3Nwu3s16.docx',

    // redemptionHttp: 'http://192.168.0.181:8080/',//本地环境(优惠券)
    //superviseHttp: 'http://192.168.0.181:8080/',//本地环境(监管端)
    //blockchainHttp: 'http://192.168.0.181:8080/',//本地环境(区块链浏览器)

    // redemptionHttp: 'https://coupon.xiaodaiyan.com/',//测试环境(优惠券)
    // superviseHttp: 'https://gov.xiaodaiyan.com',//测试环境(监管端)
    // blockchainHttp: 'https://bee.xiaodaiyan.com/beeBrowser/h5/',//测试环境(区块链浏览器)
    // applyAppealHttp: 'https://gov.xiaodaiyan.com/pages/index/appeal/applyAppeal',//测试环境(监管端-我要申诉页面)

    redemptionHttp: 'https://coupon.milianmeng.net/', //正式环境(优惠券)
    superviseHttp: 'https://hkgxq.milianmeng.net',//正式环境(监管端)
    blockchainHttp: 'https://www.milianmeng.net/beeBrowser/h5/',//正式环境(区块链浏览器)
    applyAppealHttp: 'https://hkgxq.milianmeng.net/pages/index/appeal/applyAppeal',//测试环境(监管端-我要申诉页面)

    sessionKey: '',
    phone: '',
    nickName: '',
    isRefreshList: '',
    lat: '', //维度 19.998417
    lnt: '', //经度 110.264774
    appid: 'wx0b90e972107f2559',
    source: 2, //用户来源： 1 神椰  2 卡包 3 抖音  4官网 5卡优优预付 6神椰商家端  7 诚信预付
    paySource: 1, //支付来源： 1 蜜链盟卡包 2 神椰商家端 3 诚信预付  4神椰 5 卡优优预付  6抖音小程序
  },
  gettop: {
    height: 0,
    status: 0,
    navHeight: 0,
    mobbleBottom: 0,
  },
  mobile: {
    mobbleBottom: 0
  },
  // 通过获取系统信息计算导航栏高度
  setNavSize: function () {
    var that = this,
      sysinfo = wx.getSystemInfoSync(),
      statusHeight = sysinfo.statusBarHeight,
      isiOS = sysinfo.system.indexOf('iOS') > -1,
      navHeight;
    if (!isiOS) {
      navHeight = 48;
    } else {
      navHeight = 44;
    }
    console.log('机型++++++++++', sysinfo.model)
    this.gettop.height = statusHeight + navHeight
    this.gettop.status = statusHeight
    this.gettop.navHeight = navHeight
    console.log(this.gettop.height)
    let modelmes = sysinfo.model;
    if (modelmes.search('iPhone X') != -1 || modelmes.search('iPhone XR') != -1 || modelmes.search('iPhone XS max') != -1 || modelmes.search('iPhone 11') != -1) {
      this.mobile.mobbleBottom = 50 //判断手机机型适配底部（50rpx）
      console.log('yes', this.mobile.mobbleBottom)
      //isIphoneX = true根据需求底部上升50rpx
    } else {
      this.mobile.mobbleBottom = 12
      console.log('no')
    }
  },
  //处理js精度问题
  mul(num1, num2) {
    let m = 0
    let s1 = num1.toString()
    let s2 = num2.toString()
    try {
      m += s1.split(".")[1].length
    } catch (e) {

    }
    try {
      m += s2.split(".")[1].length
    } catch (e) {}
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  },
})

// {
//   "pagePath": "pages/userStore/userStore",
//   "text": "市场1",
//   "iconPath": "/images/market-icon-no.png",
//   "selectedIconPath": "/images/market-icon.png"
// },